package com.retail.bbq.cola.controller;

import com.retail.bbq.cola.service.TencentAdCallbackService;
import com.retail.bbq.cola.vo.ResultVO;
import com.retail.bbq.cola.vo.request.TencentAdCallbackRequest;
import com.retail.bbq.cola.vo.response.TencentAdCallbackResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/tencent/ad")
public class TencentAdCallbackController {

    @Resource
    private TencentAdCallbackService tencentAdCallbackService;

    /**
     * 腾讯广告投放点击数据回传接口
     * @param request 回传请求参数
     * @return 回传结果
     */
    @PostMapping("/callback")
    public ResultVO<TencentAdCallbackResponse> callback(@RequestBody TencentAdCallbackRequest request) {
        log.info("腾讯广告回传接口调用，参数：{}", request);
        try {
            TencentAdCallbackResponse response = tencentAdCallbackService.callback(request);
            return ResultVO.succ(response);
        } catch (Exception e) {
            log.error("腾讯广告回传接口调用失败", e);
            return (ResultVO<TencentAdCallbackResponse>) ResultVO.error(500,"回传失败: " + e.getMessage());
        }
    }
    
}